<?php

class RL_Principal_Input_Cookie
{
	public $base_domain = NULL;
	public $cookie_domain = NULL;

	public function __construct ($args)
	{
		$this->params = $args['params'];
		$this->cookie_expire_days = isset($args['expire_days']) ? $args['expire_days'] : 333;
		$this->cookie_domain      = isset($args[     'domain']) ? $args[     'domain'] : NULL;
	} // end of __construct
	public function ask ()
	{
		$self = $this;
		foreach ($this->params as $k=>$v) {
			if (isset($_COOKIE[$v])) { $this->$k = $_COOKIE[$v]; }
			else {
				$self = NULL;
				break;
			}
		}
		return $self;
	} // end of function ask
	public function success ()
	{
	} // end of function success
	public function error ()
	{
		foreach ($this->params as $k=>$v) {
			if (isset($_COOKIE[$v])) {
				debug(__METHOD__." unset cookie name='{$v}', domain='{$this->cookie_domain}'");
				setcookie($v, '', time()-3600, '/', '.'.$this->base_domain);
				setcookie($v, '', time()-3600, '/', $this->base_domain);
				setcookie($v, '', time()-3600, '/', $this->cookie_domain);
			}
		}
	} // end of function error
}
